<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/27
 * Time: 15:12
 */
global $_W,$_GPC;
$weid = $_W['uniacid'];
$id = $rid = $_GPC['id'];
$name = $_GPC['nickname'];
$condition = '';

if(!empty($name)) {
    $condition = " AND nick_name like '%".$name."%' ";
}
$pindex = max(1, intval($_GPC['page']));
$psize = 20;
$sql = "SELECT * FROM ".tablename($this->lottory_user_table)." WHERE  weid=:weid AND rid=:rid".$condition." ORDER BY is_receive ASC,receive_time DESC ,lottory_id DESC,createtime ASC LIMIT ".($pindex - 1) * $psize.",{$psize}";
$list = pdo_fetchall($sql, array(':weid'=>$weid,':rid'=>$id));
if(!empty($list) && is_array($list)){
    foreach($list as &$row){
        $luckinfo = pdo_fetch("SELECT `tag_name`,`luck_name` FROM ".tablename($this->lottory_award_table)."WHERE id = :id AND weid = :weid AND rid=:rid",array(':id'=>$row['lottory_id'],':weid'=>$weid,':rid'=>$rid));
        $row['tag_name'] = $luckinfo['tag_name'];
        $row['luck_name'] = $luckinfo['luck_name'];

    }
    unset($row);
}
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($this->lottory_user_table) . " WHERE  rid=:rid AND weid=:weid", array(':rid' =>$rid,':weid'=>$weid));
$pager = pagination($total, $pindex, $psize);
include $this->template('lottory_receive');
